﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using DTO;
using BLL;

namespace Calendar
{
	public class Appointment
	{
		// info lich hen 
		private CHITIETLABO ct;
		private LICHHEN l;

		public LICHHEN L
		{
			get { return l; }
			set { l = value; }
		}
		private bool allDayEvent = false;
		private System.Drawing.Color borderColor = System.Drawing.Color.Blue;
		private System.Drawing.Color color = System.Drawing.Color.White;
		internal int conflictCount;
		private bool drawBorder = false;
		private DateTime endDate;
		private string group;
		private int layer;
		private bool locked;
		private DateTime startDate;
		private System.Drawing.Color textColor = System.Drawing.Color.White;
		private string title = "";

		public Appointment()
		{
			this.color = System.Drawing.Color.White;
			this.borderColor = System.Drawing.Color.Blue;
			this.title = "New Appointment";
		}
		public Appointment(LICHHEN l)
		{
			this.color = System.Drawing.Color.White;
			this.borderColor = System.Drawing.Color.Blue;
			this.textColor = System.Drawing.Color.White;
			BENHNHAN bnmoi = new BENHNHAN();
			bnmoi.IDBENHNHAN=l.IDBENHNHAN;
			BENHNHAN benhnhm=BENHNHANBUS.GetABN(bnmoi);
			this.title ="Bệnh nhân :"+benhnhm.HOTEN.ToString() + "\n"+ l.NOIDUNG ;
			this.l = l;
		}
		public Appointment(CHITIETLABO l,String tenncc)
		{
			this.color = System.Drawing.Color.White;
			this.borderColor = System.Drawing.Color.Blue;
			this.textColor = System.Drawing.Color.White;
			BENHNHAN bnmoi = new BENHNHAN();
			bnmoi.IDBENHNHAN = l.IDBENHNHAN;
			BENHNHAN benhnhm = BENHNHANBUS.GetABN(bnmoi);
			// lay ten nha cung cap
			if (benhnhm != null)
			{
				this.title = "Bệnh nhân :" + benhnhm.HOTEN.ToString() + "\n" + "Labo:" + tenncc + "\n" + "Lúc :" + GetTime(l.NGAYGIAO);
			}
			this.ct = l;
		}
		private string GetTime(DateTime dt)
		{
			String kq = "";
			if (dt.Hour > 0 && dt.Hour < 10)
			{
				kq = "0" + dt.Hour.ToString();
				if (dt.Minute == 0)
				{
					kq += ":00";
				}
				if (dt.Minute > 0 && dt.Minute < 10)
				{
					kq += ":0" + dt.Minute.ToString();
				}
				else
				{
					kq += ":" + dt.Minute.ToString();
				}
			}
			else if (dt.Hour == 0)
			{
				kq = "00" + dt.Hour.ToString();
				if (dt.Minute == 0)
				{
					kq += ":00";
				}
				if (dt.Minute > 0 && dt.Minute < 10)
				{
					kq += ":0" + dt.Minute.ToString();
				}
				else
				{
					kq += ":" + dt.Minute.ToString();
				}
			}
			else
			{
				kq = dt.Hour.ToString();
				if (dt.Minute == 0)
				{
					kq += ":00";
				}
				if (dt.Minute > 0 && dt.Minute < 10)
				{
					kq += ":0" + dt.Minute.ToString();
				}
				else
				{
					kq += ":" + dt.Minute.ToString();
				}

			}
			return kq;
		}
		protected virtual void OnAllDayEventChanged()
		{
		}

		protected virtual void OnBorderColorChanged()
		{
		}

		protected virtual void OnColorChanged()
		{
		}

		protected virtual void OnEndDateChanged()
		{
		}

		protected virtual void OnLockedChanged()
		{
		}

		protected virtual void OnStartDateChanged()
		{
		}

		protected virtual void OnTextColorChanged()
		{
		}

		protected virtual void OnTitleChanged()
		{
		}

		public bool AllDayEvent
		{
			get
			{
				return this.allDayEvent;
			}
			set
			{
				this.allDayEvent = value;
				this.OnAllDayEventChanged();
			}
		}

		public System.Drawing.Color BorderColor
		{
			get
			{
				return this.borderColor;
			}
			set
			{
				this.borderColor = value;
				this.OnBorderColorChanged();
			}
		}

		public System.Drawing.Color Color
		{
			get
			{
				return this.color;
			}
			set
			{
				this.color = value;
				this.OnColorChanged();
			}
		}

		public bool DrawBorder
		{
			get
			{
				return this.drawBorder;
			}
			set
			{
				this.drawBorder = value;
			}
		}

		public DateTime EndDate
		{
			get
			{
				return this.endDate;
			}
			set
			{
				this.endDate = value;
				this.OnEndDateChanged();
			}
		}

		public string Group
		{
			get
			{
				return this.group;
			}
			set
			{
				this.group = value;
			}
		}

		public int Layer
		{
			get
			{
				return this.layer;
			}
			set
			{
				this.layer = value;
			}
		}

		[DefaultValue(false)]
		public bool Locked
		{
			get
			{
				return this.locked;
			}
			set
			{
				this.locked = value;
				this.OnLockedChanged();
			}
		}

		public DateTime StartDate
		{
			get
			{
				return this.startDate;
			}
			set
			{
				this.startDate = value;
				this.OnStartDateChanged();
			}
		}

		public System.Drawing.Color TextColor
		{
			get
			{
				return this.textColor;
			}
			set
			{
				this.textColor = value;
				this.OnTextColorChanged();
			}
		}

		[DefaultValue("")]
		public string Title
		{
			get
			{
				return this.title;
			}
			set
			{
				this.title = value;
				this.OnTitleChanged();
			}
		}
	}
}
